package com.jack.controller;


import com.jack.queryParam.StudentQueryParam;
import com.jack.queryParam.StudentViolation;
import com.jack.result.PageResult;
import com.jack.result.Result;
import com.jack.pojo.Student;
import com.jack.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;


/**
 * 学生管理控制类
 */
@RestController
@RequestMapping("/students")
public class StudentController {


    @Autowired
    private StudentService studentService;

    /**
     * 新增学生
     * @param student
     * @return
     */
    @PostMapping
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return Result.success();
    }

    /**
     * 批量删除学生
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result deleteStudents(@PathVariable ArrayList<Integer> ids){
        studentService.deleteStudent(ids);
        return Result.success();
    }

    /**
     * 更新学生信息
     * @param student
     * @return
     */
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }

    /**
     * 更新学生违纪信息
     * @param stu
     * @return
     */
    @PutMapping("/violation/{id}/{score}")
    public Result updateStudentScore( StudentViolation stu){
        studentService.updateStudentScore(stu);
        return Result.success();
    }

    /**
     * 学生分页查询
     * @param studentQueryParam
     * @return
     */
    @GetMapping
    public Result pageStudents( StudentQueryParam studentQueryParam){
        PageResult<Student> stus = studentService.pageStudents(studentQueryParam);
        return Result.success(stus);
    }

    /**
     * 根据id查询学生信息
     * @return
     */
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable Integer id) {
        Student stu = studentService.getStudentById(id);
        return Result.success(stu);
    }
}
